<template>
	<view>
		<u-swiper :list="banner" radius="0" :showTitle="true" height="200" keyName="image" showTitle :autoplay="false"
			circular></u-swiper>
		<!-- <view class="section">
				<view section-title>美食推荐</view>
				<view class="foods-list">
					<view class="foods-item" v-for="(item,index) in info.foods">
						<u-image radius="10" :src="item.imageUrl" width="100%" :height="index % 2 === 0 ? 150 : 200"></u-image>
						<view>{{item.name}}</view>
						<view class="tags mt-20">
						<text v-for="v in item.tags">{{v}}</text>
						</view>
					</view>
				</view>
			</view> -->
		<view class="section">
			<view class="section-title">社区与文化</view>
			<scroll-view class="scroll-list" scroll-x="true">
				<view class="item" style="width: 200px;" v-for="item in info.communityAndCultures">
					<u-image width="100%" mode="aspectFill" radius="10" height="150" :src="item.imageUrl"></u-image>
					<text class="item-title line-2">{{item.name}}</text>
					<view class="tags mt-10">
						<text v-for="vv in item.tags">{{vv}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="section">
			<view class="section-title">文化历史</view>
			<scroll-view class="scroll-list" scroll-x="true">
				<view class="item" style="width: 200px;" v-for="item in info.historyCultures">
					<u-image width="100%" mode="aspectFill" radius="10" height="150" :src="item.mainImageUrl"></u-image>
					<text class="item-title line-2">[{{item.period}}] {{item.name}}</text>
					<view class="tags mt-10">
						<text v-for="vv in item.tags">{{vv}}</text>
					</view>
				</view>

			</scroll-view>
		</view>
		<view class="section">
			<view class="section-title">美食推荐</view>
			<scroll-view class="scroll-list" scroll-x="true">
				<view class="item" style="width: 200px;" v-for="item in info.foods">
					<u-image width="100%" mode="aspectFill" radius="10" height="150" :src="item.imageUrl"></u-image>
					<text class="item-title line-2">{{item.name}}</text>
					<view class="tags mt-10">
						<text v-for="vv in item.tags">{{vv}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getTown
	} from '@/config/api.js';
	export default {
		data() {
			return {
				info: [],
				banner: [],
			}
		},
		onLoad() {
			this.getPageData();
		},
		methods: {
			getPageData() {
				getTown().then(res => {
					this.info = res;
					this.banner = res.scenicSpots.map(item => {
						return {
							image: item.imageUrl,
							title: item.name
						};
					});
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f7f7f7;
	}

	.section {
		background-color: white;
		padding: 30rpx;
		margin-top: 30rpx;

		.section-title {
			padding: 30rpx 0;
		}
	}

	/* 横向滚动列表样式 */
	.scroll-list {
		white-space: nowrap;
		/* 防止换行 */
		width: 100%;

		/* 列表项样式 */
		.item {
			display: inline-block;
			/* 横向排列 */

			margin-right: 10px;

			/* 图片样式 */
			.item-image {
				width: 100%;
				height: 150px;
				border-radius: 8px;
			}

			/* 标题样式 */
			.item-title {
				display: block;
				margin-top: 8px;
				font-size: 14px;
				color: #333;
			}
		}


	}


	.foods-list {
		margin-left: -15rpx;
		margin-right: -15rpx;
		display: flex;
		flex-wrap: wrap;

		.foods-item {
			width: calc(50% - 30rpx);
			margin: 15rpx;

			&:nth-child(odd) {
				.u-image {
					height: 400rpx;
				}
			}
		}
	}

	.tags {
		margin-left: -10rpx;
		margin-right: -10rpx;
		display: flex;
		flex-wrap: wrap;

		text {
			display: inline-block;
			padding: 2px 8px;
			border-radius: 5px;
			background-color: lightgoldenrodyellow;
			font-size: 20rpx;
			margin: 10rpx;
		}
	}
</style>